<include file="Public/min-header"/>
<div class="wrapper">
    <!-- Content Header (Page header) -->
   <include file="Public/breadcrumb"/>
    <section class="content">
    <!-- Main content -->
    <!--<div class="container-fluid">-->
    <div class="row">
      <div class="col-sm-12">
        <div class="panel panel-default">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
                <a href="{:U('Version/index')}" class="btn btn-info pull-right" data-toggle='tooltip'data-original-title="版本列表"><i class="fa fa-list" ></i>版本列表</a>
                <if condition="$platform_set eq 1">
                    <a href="{:U('Version/add',['platform'=>2])}" class="btn btn-primary pull-right" data-toggle='tooltip'data-original-title="新增Android版本"><i class="fa fa-plus" ></i>新增Android版本</a>
                  <else/>
                    <a href="{:U('Version/add',['platform'=>1])}" class="btn btn-primary pull-right" data-toggle='tooltip'data-original-title="新增iOS版本"><i class="fa fa-plus" ></i>新增iOS版本</a>
                </if> 
            
            </div> 
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-list"></i> 添加版本 <if condition="$platform_set eq 2">(上传apk后自动识别版本号)</if> </h3>
            </div>
            <div class="panel-body">
                <form action="" method="post" onsubmit="return checkUserUpdate(this);">
                    <table class="table table-bordered">
                    <tbody>
                    <tr>
                        <td class="col-sm-2">平台:</td>
                        <td >
                            <select name="platform" class="form-control disabled">
                                <option value="{$platform_set}">{$platform[$platform_set]}</option>
                            </select>
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td class="col-sm-2">版本号:</td>
                        <td ><input type="text" class="form-control" name="app_ver" value="{$data.app_ver}" placeholder="需大于{$list[0]['app_ver']}" value="{$data.app_ver}"></td>
                        <td>例：1.0.1、1.1.99</td>
                    </tr>
                    <tr>
                        <td>版本名称:</td>
                        <td><input type="text" class="form-control" name="app_ver_name" value="{$data.app_ver_name}"></td>
                        <td>版本简称2-16位中英文均可</td>
                    </tr>

                    <tr>
                        <td class="col-sm-2">影响到发布的最后版本号:</td>
                        <td >
                            <select name="last_need_update_ver" class="form-control">
                                <option value="999999">选择需要升级到此版本的已发布版本</option>
                                <volist name="list" id="vo">
                                    <option value="{$vo.app_ver_num}">{$vo.app_ver}:{$vo.app_ver_name}</option>
                                </volist>
                            </select>
                        </td>
                        <td>之前发布的哪些版本需要强制更新到此版本，请选择最后发布的一个版本，则早于该版本的都将被强制升级</td>
                    </tr>

                    <tr>
                        <if condition="$platform_set eq 1">
                            <td>应用下载地址:</td>
                            <td>
                                <input type="text" class="form-control" name="download_url" value="{$data.download_url}">
                                <input type="hidden" class="form-control" name="app_ver_code" value="{$data.app_ver_code}">
                            </td>
                            <td>最新应用的下载地址http://xxx.com/xxxxxx</td>
                        <else/>
                            <td>上传APP安装包:</td>
                            <td>
                                <input type="text" class="form-control" name="download_url" value="{$data.download_url}">
                                <input type="hidden" class="form-control" name="app_ver_code" value="{$data.app_ver_code}">
                                <label class="btn btn-success" id="uploadAppBtn" onclick="document.getElementById('appFile').click()">上传</label>
                            </td>
                            <td>安装包要小于70M</td>
                        </if>
                    </tr>

                    <tr style="display:none;">
                        <td>是否发布:</td>
                        <td >
                            <select name="status" class="form-control">
                                <option value="0">暂不发布</option>
                                <option value="1">立即发布</option>
                            </select>
                        </td>
                        <td></td>
                    </tr>

                    <tr>
                        <td>更新提示:</td>
                        <td>
                            <textarea name="update_tissue" class="form-control">{$data.update_tissue}</textarea>
                        </td>
                        <td>设备检查到更新时的弹窗提示内容</td>
                    </tr>

                    <tr>
                        <td>更新说明:</td>
                        <td>
                            <textarea name="update_desc" class="form-control">{$data.update_desc}</textarea>
                        </td>
                        <td>版本更新的具体内容</td>
                    </tr>

                    <tr>
                        <td></td>
                        <td>
                            <input type="hidden" name="id" value="{$data.id}"/>
                            <button type="submit" class="btn btn-info">
                                <i class="ace-icon fa fa-check bigger-110"></i> 保存
                            </button>
                            <input type="reset" class="btn btn-default pull-right" value="重置">
                        </td>
                    </tr>
                    </tbody>
                </table>
                </form>

            </div>
        </div>
 	  </div> 
    </div>    <!-- /.content -->
   </section>
</div>

<style type="text/css">
 #uploadAppForm{
    display: none;
 }
</style>

<form id="uploadAppForm" enctype="multipart/form-data" method="post">
    <input type="file" name="appFile" id="appFile"/>
</form>

<script>
    $("#appFile").on("change",function(){
        var appFile = document.getElementById("appFile");
        var formData = new FormData();
            formData.append("appFile",appFile.files[0])
        $.ajax({
            url: "{:U('Version/uploadApp')}",　　　　　　　　　　//上传地址
            type: 'POST',
            dataType:'json',
            timeout : 720000, //超时时间设置，单位毫秒
            cache: false,
            data: formData,     //表单数据
            beforeSend:function(){
                layer.msg("上传中...",{
                   time: 0 //不自动关闭
                })
            },
            processData: false,
            contentType: false,
            success:function(data){
                console.log(data);
                if( data.status == 0 )
                {
                    appFile.value = '';
                    return layer.msg(data.info)
                }
                if( data.status == 1 )
                { 
                    var appInfo = data.appInfo;

                    $("input[name=app_ver]").val(appInfo.appVersion);
                    $("input[name=download_url]").val(data.url);
                    $("input[name=app_ver_name]").val(appInfo.appPackage);
                    $("input[name=app_ver_code]").val(appInfo.appVersionCode);
                    
                    return layer.msg(data.info)
                }
                
            },
            error:function(res)
            {

            }
        });
    })
</script>

</body>
</html>